package be.kuleuven.peno3.mobiletoledo.Data.Client;

import java.io.IOException;

import be.kuleuven.peno3.mobiletoledo.model.Course;

import com.google.gson.Gson;


public abstract class CourseClient extends Client {
	
	public static  Course[] getCourses(String study_programme){
		try {
			String url ="study_programme="+ study_programme +"";
			url=host+"/CourseHandler/getCourses?"+encode(url);
			String json = stringOfUrl(url);
			System.out.println(url);
			Course[] courses =new Gson().fromJson(json.toString(), Course[].class);

			return courses;
		} catch (IOException e) {
			e.printStackTrace();
			return null;
		}
	}
	public  static Course getCourse(int course_id){
		try {
			
			String url ="course_id="+ course_id;
			url=host+"/CourseHandler/getCourse?"+url;
			String json = stringOfUrl(encode(url)); 
			 Course[] courses =new Gson().fromJson(json.toString(), Course[].class);
			 if (courses!=null){
				 Course course=courses[0];
				 return course;
			 }
			 else{
				 return null;
				 }
			} 
			 catch (IOException e) {
				 e.printStackTrace();
			 }
			
			return null;
		
	}
	
	
}
